package views;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.part.ViewPart;

public class Category extends ViewPart {

	public static final String ID = "galileo.category";
	
	private static Tree tree;
	private static List<TreeItem> item;
	private Composite par;
	
	public Category() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void createPartControl(Composite parent) {
		// TODO Auto-generated method stub
		tree = retTree(parent);
		
		par = parent;
		
		tree.addListener(SWT.Selection, new Listener() {
		    public void handleEvent(Event event) {
		      String string = event.detail == SWT.CHECK ? "Checked"
		          : "Selected";
		      System.out.println(event.item + " " + string);
		    }
		});
	    /*TreeItem [] item = new TreeItem[50];
	    item[0] = new TreeItem(tree, SWT.NULL);
	    item[0].setText("Environment");
	    
	    item[1] = new TreeItem(tree, SWT.NULL);
	    item[1].setText("Body");
	    
	    item[2] = new TreeItem(tree, SWT.NULL);
	    item[2].setText("Clothers");
	    
	    item[3] = new TreeItem(tree, SWT.NULL);
	    item[3].setText("Occupations");
	    
	    item[4] = new TreeItem(tree, SWT.NULL);
	    item[4].setText("Weather");
	    
	    item[5] = new TreeItem(tree, SWT.NULL);
	    item[5].setText("Tools");
	    
	    item[6] = new TreeItem(tree, SWT.NULL);
	    item[6].setText("IT technology");
	    
	    item[7] = new TreeItem(tree, SWT.NULL);
	    item[7].setText("Sports");
	    
	    item[8] = new TreeItem(tree, SWT.NULL);
	    item[8].setText("City");
	    
	    item[9] = new TreeItem(tree, SWT.NULL);
	    item[9].setText("Crime");
	    
	    item[10] = new TreeItem(tree, SWT.NULL);
	    item[10].setText("Eat");
	    
	    item[11] = new TreeItem(tree, SWT.NULL);
	    item[11].setText("<none>");*/
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub
	}
	
	private Tree retTree(Composite parent){
		
		tree = new Tree( parent , SWT.CHECK | SWT.BORDER);
	    
	    tree.setLayoutData(new GridData(GridData.FILL_BOTH));

	    item = new ArrayList<TreeItem>();
	    for(int i=0; i<12; i++){
	    	item.add(new TreeItem(tree, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.V_SCROLL));
	    }
	    
	    item.get(0).setText("<none>");
	    item.get(1).setText("Body");
	    item.get(2).setText("Clothers");
	    item.get(3).setText("Occupations");
	    item.get(4).setText("Weather");
	    item.get(5).setText("Tools");
	    item.get(6).setText("IT technology");
	    item.get(7).setText("Sports");
	    item.get(8).setText("City");
	    item.get(9).setText("Crime");
	    item.get(10).setText("Eat");
	    item.get(11).setText("Environment");
		
		return tree;
	}

	public static void createCategory(String nameCategory){
		item.add(new TreeItem(tree, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL));
		
		item.get(item.size() - 1).setText(nameCategory);
	}
}
